// 220123 1035

// Postman测试

var express = require('express');
var app = express();

// get 2个 参数

// app.get('process_get', function (req, res) {
app.get('/process_get', function (req, res) {
	
	var response = {
		'first_name': req.query.first_name,
		'last_name': req.query.last_name,
	};
	
	console.log(response);
	res.end(JSON.stringify(response));
});

// 通过 POST 方法提交两个参数
var bodyParser = require('body-parser');

// 创建 application/x-www-form-urlencoded 编码解析
var urlencodeParser = bodyParser.urlencoded({ extended: false});

app.post('/process_post', urlencodeParser, function(req, res) {
	
	var response = {
		'first_name': req.body.first_name,
		'last_name': req.body.last_name,
	};
	
	console.log(response);
	res.end(JSON.stringify(response));
});

// 启动服务器
var server = app.listen(8888, 'localhost', function() {
	var host = server.address().address;
	var port = server.address().port;
	
	console.log('服务已启动：http://%s:%s', host, port)
});
